"""
判断上三角矩阵
"""
n = eval(input())
for i in range(0, n):
    m = eval(input())
    flag = True
    for j in range(0, m):
        list1 = list(map(int, input().split()))
        for k in range(0, m):
            if k < j:
                if list1[k] != 0:
                    flag = False
                    break
    if flag:
        print('YES')
    else:
        print('NO')